class Solution {
public:
    vector<vector<int>> generate(int r) {
        vector<vector<int>> res(r);
        for (int i = 1; i <= r; i ++ ) {
            if (i == 1) res[i - 1] = {1};
            else if (i == 2) res[i - 1] = {1, 1};
            else {
                vector<int> t;
                t.push_back(1);
                for (int j = 1; j <= i - 2; j ++ )
                    t.push_back(res[i - 2][j - 1] + res[i - 2][j]);
                t.push_back(1);
                res[i - 1] = t;
            }
        }
        return res;
    }
    
    vector<int> getRow(int rowIndex) {
        vector<vector<int>> res = generate(rowIndex + 1);
        return res[rowIndex];
    }
};
